package com.mjk.manager.api.model;

import com.mjk.common.base.constns.BeeCommonConstns;
import com.mjk.common.base.model.BaseEntity;
import com.mjk.common.core.jdbc.annotation.*;
import com.mjk.common.util.MapUtils;
import com.mjk.common.web.getway.constns.GetwayConsts;
import com.mjk.common.web.getway.restful.interceptor.GetWayInterceptorReq;
import com.mjk.manager.api.constns.ApiReturnType;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serial;
import java.util.Map;
import java.util.UUID;


@EqualsAndHashCode(callSuper = true)
@Data
@ArcSharding(table="api",userName="his")
public class ApiModel extends BaseEntity {
	
	public ApiModel() {}
	
	public ApiModel(GetWayInterceptorReq req) {
		//组装apimodel
		this.menuId = UUID.randomUUID().toString(); //apipost中的接口ID
		this.apiMethod = MapUtils.getString(req.getParams(), GetwayConsts.METHOD);
		this.apiName = MapUtils.getString(req.getRestfulParams(), GetwayConsts.INSTANCE);
		this.apiWork = MapUtils.getString(req.getRestfulParams(), GetwayConsts.INSTANCE);
		this.type = "1";
		this.requestType = ApiReturnType.NORMAL.getType();
		this.returnType = ApiReturnType.NORMAL.getType();
		this.isDynamic = "0";
		this.limterNum = 0;
	
		this.status = BeeCommonConstns.ACTIVE_STATUS;
		this.apiType = "1";
		this.url = "/ld/"+MapUtils.getString(req.getRestfulParams(), GetwayConsts.PROTOCOL)+"/"
				+MapUtils.getString(req.getRestfulParams(), GetwayConsts.VERSION)+"/"
				+this.apiWork+"?method="+this.apiMethod;
	}
	
	@Serial
	private static final long serialVersionUID = 1L;
	@ExampleField
	@Id
	private Integer id;

	
	@ExampleField
	@Filed(comment = "模块ID")
	private String modelId;
	
	@Filed(comment = "模块名称")
	private String modelName;
	
	@ExampleField
	@Filed(comment = "接口名称")
	private String apiName;
	
	
	@ExampleField
	@Filed(comment = "接口类")
		private String apiClazz;
	
	@ExampleField
	@Filed(comment = "接口类型[ 1 http 2 webservice]")
	private String apiType;
	
	@ExampleField
	@Filed(comment = "接口参数")
	private String params;
	/**
	 * 1 普通select
	 * 2 复杂类型调用 存储过程
	 */
	@Filed(comment = "接口调用类型[ 1 普通select 2 存储过程]")
	private String type;
	
	@ExampleField
	@Filed(comment = "接口对应模块")
	private String apiWork;
	
	@Filed(comment = "接口对应模块名称")
	private String apiWorkName;
	
	@ExampleField
	@Filed(comment = "接口对应方法")
	private String apiMethod;
	
	@Filed(comment = "接口对应方法名称")
	private String apiMethodName;
	
	//调用的SQL 语句
	@Filed(comment = "selece语句")
	private String selectSql;
	
	//存储过程名称
	@Filed(comment = "存储过程")
	private String procedureName;
	//
	@Filed(comment = "状态")
	private String status;
	//限流数量
	@Filed(comment = "限流数量")
	private Integer limterNum;
	//超时时间
	@Filed(comment = "接口超时")
	private Integer timeOut;
	//请求地址
	@Filed(comment = "接口地址")
	private String url;
	
	@Filed(comment = "接口入参类型[ 1json 2xml 3自定义]")
	private String requestType;//请求类型
	
	@Filed(comment = "接口出参类型[ 1json 2xml 3自定义]")
	private String returnType;//返回数据类型
	
	/**
	 * 是否需要动态生成接口 0 不需要，1 需要
	 * 0 的情况为 手动编写代码，这里只是做下展示
	 */
	@ExampleField
	@Filed(comment = " 是否需要动态生成接口 [0 不需要 1 需要]")
	private String isDynamic;
	
	
	@Filed(comment = "对应菜单id[apipost中显示的父节点Id]")
	private String menuId;

    /**
	 * 数据返回类型列表 ApiReturnType
	 */
	@Transient
	private Map<String,String> returnTypes;
	/**
	 * api生成规则 自动 和 手动 ApiReturnType
	 */
	@Transient
	private Map<String,String> apiStatus;
	/**
	 * 用于界面显示
	 */
	@Transient
	private String apipostMenuId;
	/**
	 * 用于界面显示
	 */
	@Transient
	private String parentId;
	
}
